//
//  ByCellProductDetailStoreInfo.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/2.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellProductDetailStoreInfo.h"

// vc
#import "BySotreVC.h"                   // 店铺

@implementation ByCellProductDetailStoreInfo
{
    UIImageView *_iconView;             // 商家图标
    UILabel     *_nameLabel;            // 商家名称
    UILabel     *_sellAmountLabel;      // 在售商品数量
    
    UIButton   *_intoStoreButton;       // 进店逛逛
    UIButton   *_collectButton;         // 店铺手昂
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    // 图标
    _iconView = [UIImageView new];
    _iconView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self.contentView addSubview:_iconView];

    // 商家名称
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.numberOfLines = 2;
    _nameLabel.text = @"耐克旗舰店";
    _nameLabel.font = FONT(16);
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_nameLabel];
    
    // 在售商品数量
    _sellAmountLabel = [[UILabel alloc] init];
    _sellAmountLabel.text = @"在售商品：1234件";
    _sellAmountLabel.font = FONT(13);
    _sellAmountLabel.textAlignment = NSTextAlignmentLeft;
    _sellAmountLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_sellAmountLabel];
    
    // 进店逛逛
    _intoStoreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _intoStoreButton.titleLabel.font = FONT(16);
    _intoStoreButton.layer.cornerRadius = 18;
    _intoStoreButton.layer.borderColor = BY_GOLD_COLOR.CGColor;
    _intoStoreButton.layer.borderWidth = 1;
    [_intoStoreButton setTitle:@"进店逛逛" forState:UIControlStateNormal];
    [_intoStoreButton setTitleColor:BY_GOLD_COLOR forState:UIControlStateNormal];
    [_intoStoreButton addTarget:self action:@selector(intoStore) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_intoStoreButton];
    

    // 收藏
    _collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _collectButton.titleLabel.font = FONT(16);
    _collectButton.layer.cornerRadius = 18;
    _collectButton.layer.borderColor = BY_GOLD_COLOR.CGColor;
    _collectButton.layer.borderWidth = 1;
    [_collectButton setTitle:@"收藏店铺" forState:UIControlStateNormal];
    [_collectButton setTitle:@"已收藏" forState:UIControlStateSelected];
    [_collectButton setTitleColor:BY_GOLD_COLOR forState:UIControlStateNormal];
    [_collectButton addTarget:self action:@selector(collect:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_collectButton];
    
    // 布局
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@10);
        make.bottom.equalTo(@(-10));
        make.width.equalTo(_iconView.mas_height);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(10);
        make.bottom.equalTo(_iconView.mas_centerY).offset(-8);
        make.right.equalTo(_intoStoreButton.mas_left).offset(-10);
    }];
    [_sellAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nameLabel);
        make.top.equalTo(_iconView.mas_centerY).offset(8);
        make.right.equalTo(_nameLabel);
    }];
    [_intoStoreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.height.equalTo(@36);
        make.width.equalTo(@100);
        make.bottom.equalTo(_iconView.mas_centerY).offset(-5);
    }];
    [_collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.width.height.equalTo(_intoStoreButton);
        make.top.equalTo(_iconView.mas_centerY).offset(5);
    }];
}

- (void)intoStore {
    
    BySotreVC *vc = [BySotreVC new];
    [((ByBaseVC *)self.viewController) by_normalPush:vc hasNavi:true];
}
- (void)collect:(UIButton *)button {
    
    button.selected = !button.selected;
}
@end
